{

sort UD_num date
rename quarter q_of_order
gen quarter=qofd(date)

cap drop gr_sjq
egen gr_sjq=group(HS6_main quarter s_id)
egen gr_sjm=group(HS6_main month s_id)


capture drop sample
gen sample=(n_ud==1 & S_pds==1)

label var D_sourcing "\$Relational^D_b\$" 
label var S_sourcing "\$Relational_b\$" 

eststo clear

eststo: reghdfe ln_p_inpf_sbjo   S_sourcing   ///
if sample==1, ///
abs(gr_sjq top_dest_b) vce (cluster b_id)
  quietly estadd local CTRL =".", replace  
  quietly estadd local est ="OLS", replace  
  quietly estadd local FE ="sjq,d", replace  
  quietly estadd local CTRL2 ="Yes", replace    
  quietly estadd scalar  U =  . , replace   

eststo: reghdfe ln_p_inpf_sbjo  S_sourcing  ln_q_sb_all sh_s_b sh_b_s age_buysel_month  ///
 ln_q_b_all age_buy_month  ln_q_inpf signatory ///
if sample==1, ///
abs(gr_sjq top_dest_b cohort_sb cohort_b) vce (cluster b_id)
  quietly estadd local CTRL ="\scriptsize{B,R,O}", replace  
  quietly estadd local est ="OLS", replace  
  quietly estadd local FE ="sjq,d", replace  
  quietly estadd local CTRL2 ="Yes", replace    
  quietly estadd scalar  U =  . , replace 

eststo: reghdfe w_r   S_sourcing   ///
if sample==1, ///
abs(gr_sjq top_dest_b) vce (cluster b_id)
  quietly estadd local CTRL =".", replace  
  quietly estadd local est ="OLS", replace  
  quietly estadd local FE ="sjq,d", replace  
  quietly estadd local CTRL2 ="Yes", replace    
  quietly estadd scalar  U =  . , replace   

eststo: reghdfe w_r  S_sourcing  ln_q_sb_all sh_s_b sh_b_s age_buysel_month  ///
 ln_q_b_all age_buy_month  ln_p_inpf_sbjo signatory ///
if sample==1, ///
abs(gr_sjq top_dest_b cohort_sb cohort_b) vce (cluster b_id)
  quietly estadd local CTRL ="\scriptsize{B,R,O}", replace  
  quietly estadd local est ="OLS", replace  
  quietly estadd local FE ="sjq,d", replace  
  quietly estadd local CTRL2 ="Yes", replace    
  quietly estadd scalar  U =  . , replace 

eststo: reghdfe ln_numf_HS6_UD_imp   S_sourcing   ///
if sample==1, ///
abs(gr_sjq top_dest_b) vce (cluster b_id)
  quietly estadd local CTRL =".", replace  
  quietly estadd local est ="OLS", replace  
  quietly estadd local FE ="sjq,d", replace  
  quietly estadd local CTRL2 ="Yes", replace    
  quietly estadd scalar  U =  . , replace   

eststo: reghdfe ln_numf_HS6_UD_imp  S_sourcing  ln_q_sb_all sh_s_b sh_b_s age_buysel_month  ///
 ln_q_b_all age_buy_month  ln_p_inpf_sbjo ln_q_sbjo signatory ///
if sample==1, ///
abs(gr_sjq top_dest_b cohort_sb cohort_b) vce (cluster b_id)
  quietly estadd local CTRL ="\scriptsize{B,R,O}", replace  
  quietly estadd local est ="OLS", replace  
  quietly estadd local FE ="sjq,d", replace  
  quietly estadd local CTRL2 ="Yes", replace    
  quietly estadd scalar  U =  . , replace 

esttab using "${tables}\TableD1PanelA.tex", ///
  label replace booktabs b(3) se(3) noconstant obslast substitute(\_ _) ///
  title("Buyers' Sourcing and Input Usage: Alternative Time Horizons" \label{MaterialsUsageHorizons}) ///
  drop(ln_q_b_all ln_q_sb_all sh_s_b sh_b_s age_buysel_months  age_buy_months ln_p_inpf_sbjo ln_q_sbjo ln_q_inpf signatory _cons) order( ) /// 
  stats(FE CTRL r2   N   , fmt( %~#s  %~#s 2 %12.0fc  )  ///
  labels("FEs" "Controls" `"\(R^{2}\)"'  "Obs."  ))   ///
  star(* 0.10 ** 0.05 *** 0.01) ///
  nonotes  	


eststo clear

eststo: reghdfe ln_p_inpf_sbjo   S_sourcing   ///
if sample==1, ///
abs(gr_sjm top_dest_b) vce (cluster b_id)
  quietly estadd local CTRL =".", replace  
  quietly estadd local est ="OLS", replace  
  quietly estadd local FE ="sjm,d", replace  
  quietly estadd local CTRL2 ="Yes", replace    
  quietly estadd scalar  U =  . , replace   

eststo: reghdfe ln_p_inpf_sbjo  S_sourcing  ln_q_sb_all sh_s_b sh_b_s age_buysel_month  ///
 ln_q_b_all age_buy_month  ln_q_inpf signatory ///
if sample==1, ///
abs(gr_sjm top_dest_b cohort_sb cohort_b) vce (cluster b_id)
  quietly estadd local CTRL ="\scriptsize{B,R,O}", replace  
  quietly estadd local est ="OLS", replace  
  quietly estadd local FE ="sjm,d", replace  
  quietly estadd local CTRL2 ="Yes", replace    
  quietly estadd scalar  U =  . , replace 

eststo: reghdfe w_r   S_sourcing   ///
if sample==1, ///
abs(gr_sjm top_dest_b) vce (cluster b_id)
  quietly estadd local CTRL =".", replace  
  quietly estadd local est ="OLS", replace  
  quietly estadd local FE ="sjm,d", replace  
  quietly estadd local CTRL2 ="Yes", replace    
  quietly estadd scalar  U =  . , replace   

eststo: reghdfe w_r  S_sourcing  ln_q_sb_all sh_s_b sh_b_s age_buysel_month  ///
 ln_q_b_all age_buy_month  ln_p_inpf_sbjo signatory ///
if sample==1, ///
abs(gr_sjm top_dest_b cohort_sb cohort_b) vce (cluster b_id)
  quietly estadd local CTRL ="\scriptsize{B,R,O}", replace  
  quietly estadd local est ="OLS", replace  
  quietly estadd local FE ="sjm,d", replace  
  quietly estadd local CTRL2 ="Yes", replace    
  quietly estadd scalar  U =  . , replace 

eststo: reghdfe ln_numf_HS6_UD_imp   S_sourcing   ///
if sample==1, ///
abs(gr_sjm top_dest_b) vce (cluster b_id)
  quietly estadd local CTRL =".", replace  
  quietly estadd local est ="OLS", replace  
  quietly estadd local FE ="sjm,d", replace  
  quietly estadd local CTRL2 ="Yes", replace    
  quietly estadd scalar  U =  . , replace   

eststo: reghdfe ln_numf_HS6_UD_imp  S_sourcing  ln_q_sb_all sh_s_b sh_b_s age_buysel_month  ///
 ln_q_b_all age_buy_month  ln_p_inpf_sbjo ln_q_sbjo signatory ///
if sample==1, ///
abs(gr_sjm top_dest_b cohort_sb cohort_b) vce (cluster b_id)
  quietly estadd local CTRL ="\scriptsize{B,R,O}", replace  
  quietly estadd local est ="OLS", replace  
  quietly estadd local FE ="sjm,d", replace  
  quietly estadd local CTRL2 ="Yes", replace    
  quietly estadd scalar  U =  . , replace 

esttab using "${tables}\TableD1PanelB.tex", ///
  label replace booktabs b(3) se(3) noconstant obslast substitute(\_ _) ///
  title("Buyers' Sourcing and Input Usage: Alternative Time Horizons" \label{MaterialsUsageHorizons}) ///
  drop(ln_q_b_all ln_q_sb_all sh_s_b sh_b_s age_buysel_months  age_buy_months ln_p_inpf_sbjo ln_q_sbjo ln_q_inpf signatory _cons) order( ) /// 
  stats(FE CTRL r2   N   , fmt( %~#s  %~#s 2 %12.0fc  )  ///
  labels("FEs" "Controls" `"\(R^{2}\)"'  "Obs."  ))   ///
  star(* 0.10 ** 0.05 *** 0.01) ///
  nonotes  	

}
   